package models

import (
	"fitness-srv/basic/config"
	"gorm.io/gorm"
)

// 用户表
type User struct {
	gorm.Model
	Mobile   string  `json:"mobile" gorm:"type:char(11);comment:'手机号'"`
	Password string  `json:"password" gorm:"type:varchar(32);comment:'密码'"`
	NickName string  `json:"nick_name" gorm:"type:varchar(50);comment:'昵称'"`
	Sex      int     `json:"sex" gorm:"type:int;comment:'性别 1-男 2-女'"`
	Height   int     `json:"height" gorm:"type:int;comment:'身高'"`
	Weight   float64 `json:"weight" gorm:"type:decimal(10,2);comment:'体重'"`
	BodyFat  string  `json:"body_fat" gorm:"type:varchar(30);comment:'体脂'"`
	UType    int     `json:"u_type" gorm:"type:int;comment:'类型 1-普通用户 2-商家 3-管理员'"`
	Status   int     `json:"status" gorm:"type:int;comment:'状态 1-正常 2-注销'"`
}

func (u *User) TableName() string {
	return "user"
}

func (u *User) CreateUser() error {
	return config.DB.Create(&u).Error
}

func (u *User) GetUserInfo(mobile string) error {
	return config.DB.Model(&User{}).Where("mobile = ?", mobile).Limit(1).Find(&u).Error
}

func (u *User) GetUserById(id int64) error {
	return config.DB.Model(&User{}).Where("id = ?", id).Limit(1).Find(&u).Error
}
